package com.webserver.core;

import com.webserver.controller.UserController;
import com.webserver.http.HttpServletRequest;
import com.webserver.http.HttpServletResponse;

import com.webserver.http.HttpContext;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 * 用来完成处理请求的环节
 */

public class DispatcherServlet {
    public void service(HttpServletRequest request, HttpServletResponse response) {
//        String path = request.getUri();
        String path = request.getRequestURI();

        System.out.println("抽象路径:" + path);

        if ("/myweb/reg".equals(path)) {
//            System.out.println("开始处理注册业务!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
            UserController controller = new UserController();
            controller.reg(request,response);
        } else {
            File file = new File("./webapps/" + path);
            if (file.isFile()) {
                response.setContentFile(file);
            } else {
                response.setStatusCode(404);
                response.setStatusReason("Not Found");
                file = new File("./webapps/root/404.html");
                response.setContentFile(file);
            }
        }
        response.addHeader("Server", "WebServer");

    }
}
